package com.amphiprion.prototype.component;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Canvas;

import com.amphiprion.prototype.ScreenProperty;
import com.amphiprion.prototype.component.animation.GameComponentAnimation;
import com.amphiprion.prototype.control.ControlerState;

public abstract class GameComponent {
	protected float x = 0.0f;
	protected float y = 0.0f;
	protected float scale = 1.0f;
	protected float rotation = 0.0f;
	protected int alpha = 255;
	protected boolean mustBeRemoved;

	// ANIMATION VARIABLE
	private List<GameComponentAnimation> animations;

	public GameComponent() {
		animations = new ArrayList<GameComponentAnimation>();
	}

	public void addAnimation(GameComponentAnimation animation) {
		animation.setGameComponent(this);
		animation.start();
		animations.add(animation);
	}

	public void onInput(ControlerState state, long elapsed) {
		for (int i = animations.size() - 1; i >= 0; i--) {
			GameComponentAnimation anim = animations.get(i);

			if (!anim.onUpdate(elapsed)) {
				if (anim.isRemoveComponentAtEnd()) {
					mustBeRemoved = true;
				}
				animations.remove(i);

			}
		}

	}

	public abstract void activate();

	public abstract void desactivate();

	public abstract void onDraw(Canvas canvas, ScreenProperty screenProperty);

	public void setScale(float scale) {
		this.scale = scale;
	}

	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}

	public void setAlpha(int alpha) {
		this.alpha = alpha;
	}

	public void setRotation(float rotation) {
		this.rotation = rotation;
	}

	public float getRotation() {
		return rotation;
	}

	public void setX(float x) {
		this.x = x;
	}

	public void setY(float y) {
		this.y = y;
	}

	public boolean isMustBeRemoved() {
		return mustBeRemoved;
	}

	public void clearAnimations() {
		animations.clear();
	}
}
